import { Zoom, Fullscreen, MouseLocation, Scale, MapTheme, Logo } from '@antv/l7'
export default function useControls(scene, map) {
  //添加一批控件 zoom fullscreen maptheme scale mouseposition
  const controls = {}
  controls.zoom = new Zoom({
    position: 'topleft',
  })
  controls.fullscreen = new Fullscreen()
  controls.mouselocation = new MouseLocation({ position: 'bottomright' })
  controls.scale = new Scale({
    position: 'bottomright',
  })
  controls.maptheme = new MapTheme({
    options: [
      { text: '白天导航地图', value: 'mapbox://styles/mapbox/navigation-day-v1' },
      { text: '夜间导航地图', value: 'mapbox://styles/mapbox/navigation-night-v1' },
      { text: '标记卫星地图', value: 'mapbox://styles/mapbox/satellite-streets-v12' },
      { text: '普通卫星地图', value: 'mapbox://styles/mapbox/satellite-v9' },
    ],
  })
  controls.logo = new Logo({
    img: 'http://www.x-zd.com/themes/simpleboot3_web/public/web/images/image/logo_03.png',
    href: 'http://www.x-zd.com/',
  })
  //遍历controls对象 将其中每个控件都添加到L7上
  for (const key in controls) {
    scene.addControl(controls[key])
  }
  controls.scale.hide()
  //根据zoom值的变化确定scale是否显示/隐藏 (>5显示 否则隐藏)
  map.on('zoom', () => {
    let zoom = map.getZoom()
    if (zoom > 5) {
      controls.scale.show()
    } else {
      controls.scale.hide()
    }
  })
}
